/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game;

import sengine.Sprite;
import sengine.Texture;

/**
 *
 * @author twoodf5611
 */
public class Sword extends Sprite implements Equipment, Weapon {
    private byte active = 0;
    private byte direction = 1;
    
    public Sword() {
        super(0, 0, 10, 50);
        setVx(0);
        setTexture(Texture.loadTexture("knife-right.png"));
        setPhysType(PhysicsType.FIXED);
    }
    
    @Override
    public void collideTarget(sengine.Character target) {
        System.err.println("COLLIDE");
        if(!(target instanceof sengine.PlayerCharacter) && active>0) {
            System.err.println("DIE");
            target.changeHealth(-30);
        }
    }

    @Override
    public void click(float distance, float angle) {
        active = 10;
        setR(direction*10);
    }

    @Override
    public void playerLocUpdate(float x, float y, float r, byte direction) {
        if(active > 0) {
            active -= 1;
        } else {
            setR(0);
        }
        if(direction>=0) {
            x += 31;
        }
        setX(x + direction*20);
        setY(y - 20);
        this.direction = direction;
        if(direction>=0) {
            setTexture(Texture.loadTexture("knife-right.png"));
        } else {
            setTexture(Texture.loadTexture("knife-left.png"));
        }
    }
}
